package com.lighthouse.doc.base.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lighthouse.common.tag.domain.KnowledgeTag;
import com.lighthouse.doc.comment.domain.KnowledgeDocComment;
import com.lighthouse.doc.comment.domain.KnowledgeDocCommentVO;
import com.lighthouse.doc.operate.domain.KnowledgeDocOperate;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.Builder;
import lombok.Data;
import com.ruoyi.common.annotation.Excel;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 文档信息对象 lh_doc_base_info
 *
 * @author ysz
 * @date 2023-03-22
 */
@Document(indexName = "doc-info-000001")
@Builder
@Accessors(chain = true)
@Data
public class KnowledgeDocBaseInfoVo extends KnowledgeDocBaseInfo
{
    private static final long serialVersionUID = 1L;

    /** 是否有编辑权限 */
    private boolean isCreater;

    /** 用户操作集 */
    private KnowledgeDocOperate operate;

    /** 用户评论集 */
    private List<KnowledgeDocCommentVO> comments;

    public boolean getIsCreater() {
        return isCreater;
    }

    public void setIsCreater() {
        this.isCreater = SecurityUtils.getUserId().equals(this.getCreateUser());
    }

    public KnowledgeDocOperate getOperate() {
        return operate;
    }

    public void setOperate(KnowledgeDocOperate operate, String docId) {
        // 新增时默认为N
        if (null == operate) {
            operate = KnowledgeDocOperate.builder().isCollect("N").isLike("N").isDownload("N").build();
        }
        // 确保后续对operate操作时能拿到docId
        operate.setDocId(docId);
        operate.setUserId(SecurityUtils.getUserId());
        this.operate = operate;
    }

    public List<KnowledgeDocCommentVO> getComments() {
        return comments;
    }

    public void setComments(List<KnowledgeDocCommentVO> comments) {
        this.comments = comments;
    }

    /**
     * 复制实体类返回前端
     * @author ysz
     * @param knowledgeDocBaseInfo
     * @return com.lighthouse.doc.base.domain.KnowledgeDocBaseInfoVo
     **/
    public KnowledgeDocBaseInfoVo copyVoInfo(KnowledgeDocBaseInfo knowledgeDocBaseInfo) {
        BeanUtils.copyBeanProp(this, knowledgeDocBaseInfo);
        return this;
    }
}
